package com.TT.service.mysql;

import com.TT.common.REST.TypeOfServiceResponse;
import com.TT.dao.mysql.RoomMapper;
import com.TT.domain.mysql.Room;
import com.TT.service.BaseService;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 苏文广 created at 2018/11/27
 * @Description: 房源服务
 */
@Service
public class RoomService extends BaseService {
    @Resource
    RoomMapper roomMapper;

    /**
     * 添加房源
     * @param room
     * @return
     * @throws Exception
     */
    public boolean add(Room room) throws Exception {
        try {
            int i = roomMapper.insertSelective(room);
            return TypeOfServiceResponse.BOOLEAN_SUCCESS;
        }catch (Exception e){
            tryLog(e);
            throw e;
        }
    }

//    public boolean delete(Room room) throws Exception {
//        try {
//            roomMapper.deleteByPrimaryKey(room.getRoomId());
//            return TypeOfServiceResponse.BOOLEAN_SUCCESS;
//        }catch (Exception e){
//            tryLog(e);
//            throw e;
//        }
//    }

//    public List<Room> query() throws Exception {
//        try {
//            ArrayList<Room> rooms;
//            rooms = roomMapper.selectAll();
//            return rooms;
//        }catch (Exception e){
//            tryLog(e);
//            throw e;
//        }
//    }

    public boolean update(Room room) throws Exception {
        try {
            roomMapper.updateByPrimaryKeySelective(room);
            return TypeOfServiceResponse.BOOLEAN_SUCCESS;
        }catch (Exception e){
            tryLog(e);
            throw e;
        }
    }
}
